from manim import *

class ParallelLinesProperties(Scene):
    def construct(self):
        # 创建两条平行线和一条截线
        l1 = Line(start=LEFT*3 + UP, end=RIGHT*3 + UP, color=BLUE)
        l2 = Line(start=LEFT*3 + DOWN, end=RIGHT*3 + DOWN, color=BLUE)
        t = Line(start=LEFT*2 + 2*UP, end=RIGHT*2 + 2*DOWN, color=YELLOW)
        
        # 标签
        l1_label = Tex("l1").next_to(l1, LEFT)
        l2_label = Tex("l2").next_to(l2, LEFT)
        t_label = Tex("t").next_to(t, UP)
        
        # 添加到场景中
        self.play(Create(l1), Write(l1_label))
        self.play(Create(l2), Write(l2_label))
        self.play(Create(t), Write(t_label))
        
        self.wait(2)

        # 创建同位角
        angle_a1 = Angle(t, l1, radius=0.5, quadrant=(1, 1), color=RED)
        angle_a2 = Angle(t, l2, radius=0.5, quadrant=(1, 1), color=RED)
        
        # 标签同位角
        angle_a1_label = MathTex(r"\alpha_1").next_to(angle_a1, RIGHT)
        angle_a2_label = MathTex(r"\alpha_2").next_to(angle_a2, RIGHT)
        
        # 显示同位角相等
        self.play(Create(angle_a1), Write(angle_a1_label))
        self.play(Create(angle_a2), Write(angle_a2_label))
        self.wait(1)
        self.play(Indicate(angle_a1), Indicate(angle_a2))
        same_side_text = Text("同位角相等").to_edge(DOWN)
        self.play(Write(same_side_text))
        self.wait(2)
        
        # 清除同位角
        self.play(FadeOut(angle_a1, angle_a1_label, angle_a2, angle_a2_label, same_side_text))

        # 创建内错角
        angle_b1 = Angle(t, l1, radius=0.5, quadrant=(1, 1), color=GREEN)
        angle_b2 = Angle(t, l2, radius=0.5, quadrant=(-1, -1), color=GREEN)
        
        # 标签内错角
        angle_b1_label = MathTex(r"\beta_1").next_to(angle_b1, LEFT)
        angle_b2_label = MathTex(r"\beta_2").next_to(angle_b2, RIGHT)

        # 显示内错角相等
        self.play(Create(angle_b1), Write(angle_b1_label))
        self.play(Create(angle_b2), Write(angle_b2_label))
        self.wait(1)
        self.play(Indicate(angle_b1), Indicate(angle_b2))
        alternate_interior_text = Text("内错角相等").to_edge(DOWN)
        self.play(Write(alternate_interior_text))
        self.wait(2)

        # 清除内错角
        self.play(FadeOut(angle_b1, angle_b1_label, angle_b2, angle_b2_label, alternate_interior_text))
        
        # 创建同旁内角
        angle_c1 = Angle(t, l1, radius=0.5, quadrant=(1, 1), color=BLUE)
        angle_c2 = Angle(l2, t, radius=0.5, quadrant=(1, -1), color=BLUE)
        
        # 标签同旁内角
        angle_c1_label = MathTex(r"\gamma_1").next_to(angle_c1, RIGHT)
        angle_c2_label = MathTex(r"\gamma_2").next_to(angle_c2, RIGHT)

        # 显示同旁内角互补
        self.play(Create(angle_c1), Write(angle_c1_label))
        self.play(Create(angle_c2), Write(angle_c2_label))
        self.wait(1)
        self.play(Indicate(angle_c1), Indicate(angle_c2))
        consecutive_interior_text = Text("同旁内角互补").to_edge(DOWN)
        self.play(Write(consecutive_interior_text))
        
        # 显示角度和为180度
        sum_text = MathTex(r"\gamma_1 + \gamma_2 = 180^\circ").next_to(consecutive_interior_text, UP)
        self.play(Write(sum_text))
        self.wait(2)

        # 清除同旁内角
        self.play(FadeOut(angle_c1, angle_c1_label, angle_c2, angle_c2_label, consecutive_interior_text, sum_text))